const { toUrl } = getApp()
import { request, baseUrl } from '@/utils/request'

Component({
    properties: {
        on: { type:Number, value:0 }
    },
    toggle () {},
    data: {
        list: [
            { 
                title: '首页', icon: '/image/foot1.png', 
                selectIcon: '/image/foot1-1.png',
                url: '/pages/home/home' 
            },
            { 
                title: '找店', icon: '/image/foot2.png', 
                selectIcon: '/image/foot2-1.png', 
                url: '/pages/store/list' 
            },
            // { title: '', icon: '/image/foot3.png' },
            { 
                title: '停车', icon: '/image/foot4.png', 
                selectIcon: '/image/foot4-1.png',
                url: '/pages/park/park' 
            },
            { title: '我的', icon: '/image/foot5.png', selectIcon: '/image/foot5-1.png', url: '/pages/me/me'  }
        ]
    },
    methods: {
        scan () {
            wx.scanCode({
                success: (res) => {
                    const { result } = res
                    console.log(res);
                    try {
                        let data = JSON.parse(result)
                        // let data = result
                        request('order/writeoffcodetoid', { data: { writeoff_code:data.writeoff_code } }).then((res) => {
                            if (res.errcode == 1) {
                                console.log(res.data.order_id);
                                wx.redirectTo({
                                  url: `/pages/order/detail?order_id=${res.data.order_id}&admins=1`,
                                })
                            }else{
                                wx.showToast({
                                  title: res.message,
                                })
                                setTimeout(() => {
                                    wx.navigateBack({
                                        delta:1
                                    })
                                }, 200);
                            }
                            // const { title, content } = data
                            
                        })
                    }catch {
                        console.log('not json')
                        wx.navigateTo({
                          url: '/pages/webview/webview?url='+result,
                        })
                    }
                    
                }
            })
        },
        toUrl
    }
})
